<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	//include ROOTPATH .'include'. DS .'isMyQuery.php';
	$do					= getQuery('do') ;
	$file 				= $_FILES['Filedata'];
	
	switch($do){
		case 'uploadMediaThumb' 	: uploadMediaThumb($file) ;
		break;
		
		case 'uploadFile' 			: uploadFile($file) ;
		break;
		
		case 'uploadUserFace' 		: uploadUserFace($file) ;
		break;
		

	}



function uploadMediaThumb($file){
	$upload = new upload ;
	$upload -> checkSize($file,MAX_PHOTO_SIZE);
	
	$userUploadPhoto = new userUploadPhoto();
	
	$saveName = date('His') . rand(10000,99999) . rand(10000,99999) ;
	$savePath = TMP_PATH . creatFolder(TMP_PATH);
	$array['photo'] = $userUploadPhoto -> uploadUserFace($file, $savePath, $saveName ,MEDIA_THUMB_WIDTH,MEDIA_THUMB_HEIGHT,MAX_PHOTO_SIZE);
	exit(ROOT_PATH.$array['photo']) ;
}


function uploadFile($file){
	$upload = new upload ;
	$upload -> checkSize($file,100*1024*1024);	
	$savePath = TMP_PATH . creatFolder(TMP_PATH);
	$saveName = date('His') . rand(10000,99999) . rand(10000,99999) ;
	$path = $upload -> files($file,$savePath,$saveName,true);
	echo ROOT_PATH.$path;
}

function uploadUserFace($file){
	$upload = new upload ;
	$upload -> checkSize($file,MAX_PHOTO_SIZE);
	
	$userUploadPhoto = new userUploadPhoto();
	
	$saveName = date('His') . rand(10000,99999) . rand(10000,99999) ;
	$savePath = TMP_PATH . creatFolder(TMP_PATH);
	$array['photo'] = $userUploadPhoto -> uploadUserFace($file, $savePath, $saveName ,USERFACE_BIG_WIDTH,USERFACE_BIG_HEIGHT,MAX_PHOTO_SIZE);
	
	
	
	$smallPhoto = array( 0 => $array['photo']);
	$smallPhoto = moveUploadFile($smallPhoto, TMP_PATH ,'copy' );
	
		
	$saveName = md5(time() . rand(1000000,9999999) . rand(10000,99999) ) ;
	$savePath = TMP_PATH . creatFolder(TMP_PATH);
	//$newPhoto = new userUploadPhoto ;
	$smallPhoto = $userUploadPhoto -> cropUserPhoto($smallPhoto, $savePath , $saveName , USERFACE_SMALL_WIDTH , USERFACE_SMALL_HEIGHT , 'copy' );	
	exit('<img src="'. ROOT_PATH.$array['photo'] .'" url="'.ROOT_PATH.$array['photo'].'" /> <img src="'. ROOT_PATH.$smallPhoto .'" url="'.ROOT_PATH.$smallPhoto .'" />') ;
}
	           
?>